﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using l1cs.server.model;

namespace l1cs.server.serverpackets
{
    public class S_HPMeter : ServerBasePacket
    {
        private byte[] _byte = null;

        public S_HPMeter( int objId, int hpRatio )
        {
            buildPacket( objId, hpRatio );
        }

        public S_HPMeter( L1Character cha )
        {
            int objId = cha.getId();
            int hpRatio = 100;
            if ( 0 < cha.getMaxHp() )
            {
                hpRatio = 100 * cha.getCurrentHp() / cha.getMaxHp();
            }

            buildPacket( objId, hpRatio );
        }

        private void buildPacket( int objId, int hpRatio )
        {
            writeC( Opcodes.S_OPCODE_HPMETER );
            writeD( objId );
            writeC( hpRatio );
        }

        override
        public byte[] getContent()
        {
            if ( _byte == null )
            {
                _byte = _bao.ToArray();
            }

            return _byte;
        }

        override
        public String getType()
        {
            return "[S] S_HPMeter";
        }
    }
}
